package com.pactera.madp.cp.service.sync.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pactera.madp.cp.api.entity.sync.SyncPsnInfoHisEntity;
import com.pactera.madp.cp.mapper.sync.SyncPsnInfoHisMapper;
import com.pactera.madp.cp.service.sync.SyncPsnInfoHisService;
import org.springframework.stereotype.Service;

@Service
public class SyncPsnInfoHisServiceImpl extends ServiceImpl<SyncPsnInfoHisMapper, SyncPsnInfoHisEntity> implements SyncPsnInfoHisService {

    @Override
    public void syncOneDay(String syncDate) {
        // 插入历史表前，删除可能存在的上一天数据
        this.remove(Wrappers.<SyncPsnInfoHisEntity>lambdaQuery()
                .eq(SyncPsnInfoHisEntity::getSyncDate, syncDate));
        // 同步上一天数据到历史表
        baseMapper.syncData(syncDate);
    }

    @Override
    public void deleteOneDate(String date) {
        this.remove(Wrappers.<SyncPsnInfoHisEntity>lambdaQuery()
                .le(SyncPsnInfoHisEntity::getSyncDate, date));
    }

}